package com.open.rbac.model.entity.sys;

import java.time.LocalDate;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

import com.open.center.jpa.model.entity.IdEntity;
import com.open.rbac.constant.GenderType;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@DynamicUpdate
@SQLRestriction("is_deleted = false")
@SQLDelete(sql = "UPDATE user SET is_deleted = 1 WHERE id = ?")
@Entity(name = "user")
public class User extends IdEntity {

    @Column(name = "username", nullable = false, length = 50)
    private String username;

    @Column(name = "password", nullable = false)
    private String password;

    @Column(name = "realname", nullable = false, length = 50)
    private String realname;

    @Convert(converter = GenderType.Converter.class)
    @Column(name = "gender", nullable = false, length = 10)
    private GenderType gender;

    @Column(name = "birthday", nullable = false)
    private LocalDate birthday;

    @Column(name = "phone", nullable = false, length = 15)
    private String phone;

    @Column(name = "email")
    private String email;

    @Column(name = "avatar")
    private String avatar;

    @Column(name = "enable", nullable = false)
    private Boolean enable;

    @Column(name = "remark", nullable = false)
    private String remark;

}
